package com.yoso.starter.boot.enums;

import lombok.Getter;

/**
 * <p>
 *   文件类型
 * </p>
 *
 * @author shizejin
 * @version 1.0
 * @date 2023/5/24 9:37
 */
public enum FileTypeEnum {
    EXCEL(1, "Excel文件", ".xlsx"),

    TEXT(2, "文本文件", ".text"),

    JSON(3, "json文件", ".json"),
    ZIP(4, "zip文件", ".zip");


    @Getter
    private final Integer code;
    @Getter
    private final String name;
    @Getter
    private final String suffix;

    FileTypeEnum(Integer code, String name, String suffix) {
        this.code = code;
        this.name = name;
        this.suffix = suffix;
    }

    public static FileTypeEnum getByCode(Integer code) {
        FileTypeEnum[] enums = values();
        for (FileTypeEnum typeEnum : enums) {
            if (typeEnum.getCode().equals(code)) {
                return typeEnum;
            }
        }
        return null;
    }

    public static FileTypeEnum getBySuffix(String suffix) {
        FileTypeEnum[] enums = values();
        for (FileTypeEnum typeEnum : enums) {
            if (typeEnum.getSuffix().equals(suffix) || typeEnum.getSuffix().equals("." + suffix)) {
                return typeEnum;
            }
        }
        return null;
    }
}